package controllers;

import java.util.List;

import org.omg.CORBA.REBIND;

import service.OrdcomService;

import models.Ordcom;
import models.Orwrba;

@CRUD.For(Ordcom.class)
public class Ordcoms extends CRUD {
	public static void findordcoms(Long id){
		List<Ordcom> ordcomlist = OrdcomService.findAll(id);
		render("/Ordcoms/ordcomsList.html",ordcomlist,id);
	}
	
	public static void selOrder(Long orid){
		Ordcom ord=OrdcomService.onlyone(orid);
		render("/Ordcoms/backOrder.html",ord,orid);
	}
	
	public static void selallOrw(String orid,String indid){
		System.out.println(orid+"-------------------------------------------------");
		List<Orwrba> orwrbaList = OrdcomService.findAllorw(orid); 
		render("/Orwrbas/orwrbalist.html",orwrbaList,orid,indid);
	}
	
	public static void delordcom(String id){
		System.out.println();
		int state = 0 ; 
		
		int res = OrdcomService.delord(id);
		if(res >0){
			state = 1;
		}else{
			state = 0 ;
		}
		render(state);
	}
	
	//评论回复
	public static void borwobas(String bcontent ,String orid){
		int state = 0 ;
		try{
			Orwrba orwrba = new Orwrba();
			orwrba.manid = "4" ;
			orwrba.ordid = orid;
			orwrba.orwdet = bcontent ;
			orwrba.save();
			state = 1 ;
			render(state);
		}catch(Exception e){
			e.printStackTrace();
			state = 0 ;
			render(state);
			
		}
	}
	
	//删除评论回复
	public static void delowrba(String id){
		int state = 0 ;
		int res = OrdcomService.delowr(id);
		if(res > 0){
			state = 1 ;
			render(state);
		}else{
			state = 0 ;
			render(state);
		}
		render(state);
	}
	
}
